/**
* Class to manage generic inserts into DB to be executed in the Servlet
*
* Project: idbCrownInServer
* Author:  TM
* Date:    05/04/2013
*
* History
* ------------------
* 05/04/2013 - TM - Initial version.
*/
 
 
package Functions;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import Application.*;
import DataModel.*;

public class insert extends genericFunction
{
    /** data to fullfill header content */
    protected Object[][] readData;
    protected String     query;
    /** Class attributes */
    protected libSQLUtil sqlUtil;


     /** Constructor  */
    public insert(HttpServletRequest _request, HttpServletResponse _response) throws IOException, ServletException
    {
       super(_request, _response);
    }
    
    /** Execute function */
    public String execute()
    {
      String result = "0";
      query = getRequest().getParameter("query");

      // Now do the real work ....
      try
      {
        sqlUtil  = libSQLUtil.getInstance();
        readData = sqlUtil.select(query);
        result   = readData[0][2] != null ? readData[0][2].toString() : "No success";
        System.out.println("Read from DB:"+result);
        
        sendResponse(result);
      }
      catch(Exception ex)
      {
        sendError(ex);
      }
      
      // After the work is done, send the reply out ....
      return result;
    }
}